package com.zhizuobiao.coura.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhizuobiao.coura.stockhelper.R;
import com.zhizuobiao.coura.weather.Weather;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by coura on 2016/12/29.
 */

public class WeatherDetailAdapter extends BaseAdapter {

    private Context context;
    private List<Weather.ResultsBean.IndexBean> list;

    public WeatherDetailAdapter(Context context, List<Weather.ResultsBean.IndexBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.weatherdetail_listview, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        holder.tvTitle.setText(list.get(position).getTitle());
        holder.tvZs.setText(list.get(position).getZs());
        holder.tvWeatherTips.setText(list.get(position).getDes());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_zs)
        TextView tvZs;
        @BindView(R.id.tv_weather_tips)
        TextView tvWeatherTips;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
